package com.example.test.advice.第十一章_开源世界.建议141_apache扩展包;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

public class Person {
    public String name;

    public int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    //自定义输出格式
    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("姓名",name)
                .append("年龄",age)
                .toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        //只有姓名相同，就让认为两个对象相等
        //return age == person.age && Objects.equal(name, person.name);
        return new EqualsBuilder()
                .appendSuper(super.equals(o))
                .append(name,person.getName())
                .isEquals();
    }

    @Override
    public int hashCode() {
        //return Objects.hashCode(name, age);

        return HashCodeBuilder.reflectionHashCode(this);
    }

}
